<template>
  <div class="aui-card--fill scroll-box card-box">
    <div class="mod-sys__user pane-shell"
         v-show="isMain">
      <search @sumbit='search'>
        <template slot='form'>
          <el-form :inline="true"
                   @submit.native.prevent
                   :model="dataForm"
                   ref="dataForm"
                   @keyup.enter.native="search">
            <el-form-item prop="username"
                          :rules="stringRule(false)">
              <el-input v-model.trim="dataForm.username"
                        placeholder="账号"
                        clearable></el-input>
            </el-form-item>
            <el-form-item prop="realName"
                          :rules="stringRule(false)">
              <el-autocomplete v-model.trim="dataForm.realName"
                               placeholder="姓名/工号/首字母选择"
                               @select="handleSelect"
                               :fetch-suggestions="querySearch"
                               clearable></el-autocomplete>
            </el-form-item>
            <el-form-item prop="phone"
                          :rules="stringRule(false)">
              <el-input v-model.trim="dataForm.phone"
                        placeholder="手机号"
                        clearable></el-input>
            </el-form-item>
            <el-form-item class="addBtn">
              <!-- <div class="user-switch">
            <span class="message-title">短信开关</span>
            <el-switch v-model="switchType.sign"
                       :active-value='1'
                       :inactive-value='0'
                       active-color="#13ce66"
                       inactive-color="#ff4949"
                       @change="switchChange">
            </el-switch>
          </div> -->
            </el-form-item>
          </el-form>
        </template>
        <template slot='btns'>
          <el-button type="primary"
                     plain
                     v-if="loadings"
                     v-loading="loadings"
                     icon="el-icon-plus">用户同步中</el-button>
          <el-button type="primary"
                     plain
                     icon="el-icon-plus"
                     @click="addwin()">新增</el-button>
          <el-dropdown style="margin-left: 15px"
                       @command="handleCommand">
            <el-button type="primary">
              更多功能<i class="el-icon-arrow-down el-icon--right"></i>
            </el-button>
            <el-dropdown-menu slot="dropdown">
              <el-dropdown-item :command="1">
                同步冲突修改记录
              </el-dropdown-item>
              <el-dropdown-item :command="2"
                                v-if="$hasPermission('system:sysUser:manyBinding')">
                批量设置权限
              </el-dropdown-item>
              <el-dropdown-item :command="3"
                                v-loading="loadings"
                                icon="el-icon-refresh">同步用户
              </el-dropdown-item>
              <el-dropdown-item :command="4"
                                icon="el-icon-refresh">
                配置同步指纹设备
              </el-dropdown-item>
              <el-dropdown-item :command="5"
                                v-if="userId == 715161385118408704">
                配置初始密码(全局)
              </el-dropdown-item>
            </el-dropdown-menu>
          </el-dropdown>
          <!-- <el-button type="primary"
                     v-if="$hasPermission('system:sysUser:getUserPage')"
                     @click="search">{{ $t('query') }}</el-button> -->
          <!-- <el-button type="primary"
                           plain
                           @click="addPage()">同步冲突修改记录</el-button> -->
          <!-- <el-button type="primary"
                           plain
                           v-if="$hasPermission('system:sysUser:manyBinding')"
                           @click="openPartitionSetting">批量设置权限</el-button> -->
          <!-- <el-button type="primary"
                           plain
                           v-loading="loadings"
                           icon="el-icon-refresh"
                           @click="addUser()">同步数据</el-button> -->
          <!-- <el-button type="primary"
                           plain
                           icon="el-icon-refresh"
                           @click="addDevice()">配置同步指纹设备</el-button> -->
        </template>
      </search>
      <table-template :tableData='tableData'
                      :loading='dataListLoading'
                      :fieldManagement='false'
                      :index='true'
                      :dataList='dataList'>
        <template slot="realName-after">
          <el-table-column prop="gender"
                           label="性别"
                           header-align="center"
                           align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.gender === 0">男</span>
              <span v-else-if="scope.row.gender === 1">女</span>
              <span v-else>未知</span>
            </template>
          </el-table-column>
        </template>
        <template slot="remarks-after">
          <el-table-column prop="source"
                           label="来源"
                           header-align="center"
                           align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.source === 1">同步</span>
              <span v-if="scope.row.source === 2">新增</span>
            </template>
          </el-table-column>
        </template>
        <template slot="remarks-before">
          <el-table-column prop="status"
                           :label="$t('user.status')"
                           header-align="center"
                           align="center">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.status"
                         :disabled="!$hasPermission('system:sysUser:updateStatus')"
                         :active-value="1"
                         :inactive-value="0"
                         active-color="#13ce66"
                         inactive-color="#ff4949"
                         @change="setStatus($event,scope.row.id)">
              </el-switch>
            </template>
          </el-table-column>
        </template>
        <template slot="remarks-before">
          <el-table-column prop="showPage"
                           label="默认主页"
                           header-align="center"
                           align="center">
            <template slot-scope="scope">
              <el-switch v-model="scope.row.showPage"
                         :active-value="1"
                         :inactive-value="0"
                         active-color="rgb(0, 157, 255)"
                         inactive-color="rgb(224, 224, 224)"
                         @change="setHomePage($event,scope.row)">
              </el-switch>
            </template>
          </el-table-column>
        </template>
        <el-table-column :label="$t('handle')"
                         fixed="right"
                         header-align="center"
                         align="center"
                         width="250">
          <template slot-scope="scope">
            <el-button type='text'
                       class='brand'
                       v-if="scope.row.source === 2 && $hasPermission('system:sysUser:update')"
                       @click='addwin(scope.row)'
                       size='small'>修改</el-button>
            <el-button type="text"
                       size="small"
                       class="danger"
                       v-if="scope.row.source === 2 && $hasPermission('system:sysUser:del')"
                       @click="deleteHandle({id:scope.row.id})">{{ $t('delete') }}</el-button>
            <el-button type='text'
                       class='brand'
                       v-if="$hasPermission('system:sysPermission:bindingPermission')"
                       @click='openPermission(scope.row.id, scope.row.username)'
                       size='small'>权限设置</el-button>
            <el-dropdown class='brand'
                         style="margin-left: 10px;"
                         @command="moreHandle">
              <span class="el-dropdown-link">
                更多操作<i class="el-icon-arrow-down el-icon--right"></i>
              </span>
              <el-dropdown-menu slot="dropdown">
                <el-dropdown-item v-if="$hasPermission('tb:user:renlian')"
                                  :command="beforeHandleCommand(scope.row, 1)">人脸</el-dropdown-item>
                <el-dropdown-item v-if="$hasPermission('tb:user:zhiwen')"
                                  :command="beforeHandleCommand(scope.row, 2)">指纹</el-dropdown-item>
                <el-dropdown-item :command="beforeHandleCommand(scope.row, 3)">卡片</el-dropdown-item>
                <!-- <el-dropdown-item v-if="$hasPermission('system:sysPermission:bindingPermission')"
                                  :command="beforeHandleCommand(scope.row, 4)">权限设置</el-dropdown-item> -->
                <el-dropdown-item v-if="$hasPermission('system:sysUser:resetPassword')"
                                  :command="beforeHandleCommand(scope.row, 5)">重置密码</el-dropdown-item>
                <el-dropdown-item :command="beforeHandleCommand(scope.row, 6)">门禁授权</el-dropdown-item>
              </el-dropdown-menu>
            </el-dropdown>
            <!-- <el-button type="text"
                       size="small"
                       v-if="$hasPermission('system:sysUser:getUserLogPage')"
                       @click="openOperation(scope.row.id)">操作记录</el-button>
            <el-button type="text"
                       size="small"
                       v-if="$hasPermission('system:sysUser:updateUser')"
                       @click="editUser(scope.row.id)">{{ $t('update') }}</el-button>
            <el-button type="text"
                       size="small"
                       class="danger"
                       v-if="($store.state.user.id !== scope.row.id && $hasPermission('system:sysUser:delUser'))"
                       @click="deleteHandle({id:scope.row.id})">{{ $t('delete') }}</el-button> -->
          </template>
        </el-table-column>
      </table-template>

      <el-pagination :current-page="page"
                     :page-sizes="[10, 20, 50, 100]"
                     :total="total"
                     layout="total, sizes, prev, pager, next"
                     @size-change="pageSizeChangeHandle"
                     @current-change="pageCurrentChangeHandle">
      </el-pagination>
      <el-dialog :visible.sync='passwordSycnDialog'
                 width="30%"
                 title="配置初始密码"
                 class="user-dialog add-or-updata"
                 :append-to-body="true"
                 :before-close="handleClose"
                 :close-on-press-escape="false"
                 :close-on-click-modal="false">
        <template>
          <el-form :model="data"
                   :rules="dataRule"
                   ref="data"
                   @keyup.enter.native="dataActionSubmitHandle()">
            <!-- <el-form-item prop="value"
                          :rules="required()"
                          label="用户初始密码">
              <el-input v-model.trim="data.value"
                        maxlength="20"
                        placeholder="请输入用户初始密码"></el-input>
            </el-form-item> -->
            <el-form-item prop="value"
                          label="用户初始密码">
              <el-input v-model.trim="data.value"
                        placeholder="请输入用户初始密码"></el-input>
            </el-form-item>
            <!-- <el-form-item prop="confirm"
                          label="">
              <el-input v-model.trim="data.confirm"
                        type="password"
                        :placeholder="$t('updatePassword.comfirmPassword')"></el-input>
            </el-form-item> -->
          </el-form>
        </template>
        <template slot="footer">
          <el-button @click="handleClose()">{{ $t('cancel')}}</el-button>
          <el-button type="primary"
                     @click="dataActionSubmitHandle()">{{ $t('confirm')}}</el-button>
        </template>
      </el-dialog>
      <!-- <el-dialog :visible.sync='setHomePageDialog'
                 width="30%"
                 title="配置主页"
                 class="user-dialog add-or-updata"
                 :append-to-body="true"
                 :before-close="handleClose1"
                 :close-on-press-escape="false"
                 :close-on-click-modal="false">
        <template>
          <el-radio-group v-model="modelSelect"
                          lable="设置是否显示主页">
            <el-radio :label="0">否</el-radio>
            <el-radio :label="1">是</el-radio>
          </el-radio-group>
        </template>
        <template slot="footer">
          <el-button @click="handleClose1()">{{ $t('cancel')}}</el-button>
          <el-button type="primary"
                     @click="dataActionSubmitHandle1()">{{ $t('confirm')}}</el-button>
        </template>
      </el-dialog> -->
      <!-- 弹窗, 新增 / 修改 -->
      <add-or-update ref="addOrUpdate"
                     @callBack="getDataList"></add-or-update>
      <!-- 操作记录 -->
      <user-operation-record ref="userOperationRecord" />
      <!-- 权限设置 -->
      <permission ref="permission" />
      <!-- 职业设置 -->
      <partition-setting ref="partitionSetting" />
      <userface ref="userface"
                @callBack="getDataList" />
      <userfingerprint ref="userfingerprint"
                       @callBack="getDataList" />
      <usererrorList ref="usererrorList"
                     @callBack="getDataList" />
      <usererrorPage ref="usererrorPage"
                     @callBack="getDataList" />
      <!-- 配置同步指纹设备 -->
      <syncfingerDevice ref="syncfingerDevice"
                        @callBack="getDataList" />
      <!-- 卡片 -->
      <card ref="card"
            @callBack="getDataList" />
    </div>
  </div>
</template>
<script>
import mixinViewModule from '@/mixins/view-module'
import formValidate from '@/mixins/form-validate'
import Search from '@/components/search/search'
// import Qs from 'qs'
import addOrUpdate from './user-add-or-update'
import userOperationRecord from './user-operation-record'
import Permission from './permission'
import PartitionSetting from './partition-setting.vue'
import tableTemplate from '@/components/table-template'
import userface from './user-face.vue'
import userfingerprint from './user-fingerprint.vue'
import usererrorList from './user-errorList.vue'
import usererrorPage from './user-errorPage.vue'
import syncfingerDevice from './sync-finger-device.vue'
import card from './user-card.vue'
export default {
  mixins: [mixinViewModule, formValidate],
  data () {
    return {
      isDisabled: true,
      user: {},
      mixinViewModuleOptions: {
        updateMessageStatusURL: '/tb/globalSign/updateStatus', // 更新短信状态
        // getBySurfaceNameURL: '/tb/globalSign/getBySurfaceName', // 获取短信状态
        updateStatusURL: '/system/sysUser/updateStatus', // 修改状态
        resetPasswordURL: '/system/sysUser/resetPassword', // 重置密码
        getDeptListURL: '/system/sysUser/getDeptInUser',
        getDistrictInUserURL: 'system/sysUser/getDeptInUser',
        getDataListURL: '/system/sysUser/getUserPage',
        getDataListIsPage: true,
        deleteURL: 'system/sysUser',
        deleteIsBatch: true
      },
      userId: this.$store.state.user.id,
      passwordSycnDialog: false,
      setHomePageDialog: false,
      modelSelect: 0,
      userData: {},
      deptListVisible: false,
      areaListVisible: false,
      deptList: [],
      areaList: [],
      loading: null,
      addVisible: false,
      dialogFormVisible: false,
      isMain: true,
      switchType: {},
      dataForm: {
        districtName: '',
        username: '',
        deptName: '',
        phone: ''
      },
      data: {
        value: ''
      },
      loadings: false
    }
  },
  mounted () {
    // this.getDistrictInUser()
    // this.getDeptList()
    // this.getMessageStatus()
  },
  components: {
    Search,
    addOrUpdate,
    userOperationRecord,
    Permission,
    PartitionSetting,
    tableTemplate,
    userface,
    userfingerprint,
    usererrorList,
    usererrorPage,
    syncfingerDevice,
    card
  },
  computed: {
    tableData () {
      return [
        { label: '账号/工号', width: '120', prop: 'username' },
        { label: '真实姓名', width: '100', prop: 'realName' },
        { label: '手机号', width: '100', prop: 'phone' },
        { label: '电子邮箱', width: '120', prop: 'email' },
        { label: '部门', width: '100', prop: 'deptName' },
        // { label: '所属地区', prop: 'districtName' },
        { label: '职位', width: '100', prop: 'positionName' },
        { label: '备注', width: '120', prop: 'remarks' },
        { label: '更新人', width: '100', prop: 'updaterName' },
        { label: '更新时间', width: '150', prop: 'updateDate' },
        { label: '创建人', width: '100', prop: 'creatorName' },
        { label: '创建时间', width: '150', prop: 'createDate' }
      ]
    },
    dataRule () {
      // let validateComfirmPassword = (rule, value, callback) => {
      //   if (this.dataForm.newPassword !== value) {
      //     return callback(new Error(this.$t('updatePassword.validate.comfirmPassword')))
      //   }
      //   callback()
      // }

      let validatePassword = (rule, value, callback) => {
        if (value === '') {
          callback(new Error('请输入密码'))
        } else if (value.length > 16) {
          callback(new Error('请输入8-16位,包括大写字母,小写字母,数字'))
        } else {
          // let pPattern = /^.*(?=.*\d)(?=.*[A-Z])(?=.*[a-z]).{8,16}/
          let pPattern = /^.*(?=.*\d)(?=.*[a-z]).{8,16}/
          // let order = 0 // 顺序
          if (pPattern.test(value)) {
            callback()
          } else {
            callback(new Error('请输入8-16位,包括大写字母,小写字母,数字'))
          }
        }
      }
      return {
        value: [
          { required: true, message: this.$t('validate.required'), trigger: 'change' },
          { validator: validatePassword, trigger: 'change' }
        ]
      }
    }
  },
  methods: {
    toDoor () {
      this.$router.push({ name: 'accessControlManagement-accessControl-empower-accessControl-empower', path: './accessControlManagement-accessControl-empower-accessControl-empower' })
      if (!this.$route.meta.isTab) {
        return false
      }
      var tab = this.$store.state.contentTabs.filter(item => item.name === this.$route.name)[0]
      if (!tab) {
        tab = {
          ...window.SITE_CONFIG['contentTabDefault'],
          ...this.$route.meta,
          'name': this.$route.name,
          'params': { ...this.$route.params },
          'query': { ...this.$route.query }
        }
        this.$store.state.contentTabs = this.$store.state.contentTabs.concat(tab)
      }
      this.$store.state.sidebarMenuActiveName = tab.menuId
      this.$store.state.contentTabsActiveName = tab.name
    },
    beforeHandleCommand (_row, command) {
      return {
        row: _row,
        command
      }
    },
    moreHandle (val) {
      if (val.command === 1) { // 人脸
        this.addWinFace(val.row)
      } else if (val.command === 2) { // 指纹
        this.addWinFingerprint(val.row)
      } else if (val.command === 3) { // 卡片
        this.addWinCard(val.row)
      } else if (val.command === 4) { // 权限设置
        this.openPermission(val.row.id, val.row.username)
      } else if (val.command === 5) { // 重置密码
        this.resetPassword(val.row.id)
      } else if (val.command === 6) { // 门禁授权
        this.toDoor(val.row)
      }
    },
    handleCommand (val) {
      if (val === 1) { // 同步冲突修改记录
        this.addPage()
      } else if (val === 2) { // 批量设置权限
        this.openPartitionSetting()
      } else if (val === 3) { // 同步数据
        this.addUser()
      } else if (val === 4) { // 配置同步指纹设备
        this.addDevice()
      } else if (val === 5) { // 设置初始密码
        this.passwordSycnDialog = true
        this.getSysGlobalConfig()
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
        })
      }
    },
    // 打开新增用户界面
    addwin (_row) {
      if (_row) {
        this.$refs.addOrUpdate.init(_row)
      } else {
        this.$refs.addOrUpdate.init()
      }
    },
    // 打开配置同步指纹设备
    addDevice () {
      this.$refs.syncfingerDevice.init()
    },
    // 打开批量设置权限
    openPartitionSetting () {
      this.$refs.partitionSetting.init()
    },
    // 打开操作记录
    openOperation (id) {
      this.$refs.userOperationRecord.init({ id })
    },
    // 打开权限设置
    openPermission (id, username) {
      this.$refs.permission.init({ id, username })
    },
    statusBoolean (data) {
      return !!data
    },
    onClose () {
      this.dataForm.deptId = ''
      this.dataForm.deptName = ''
    },
    onDistrictClose () {
      this.dataForm.districtName = ''
      this.dataForm.districtId = ''
    },
    handleClose () {
      this.passwordSycnDialog = false
    },
    // 修改全局密码
    dataActionSubmitHandle () {
      let obj = {}
      obj.type = this.data.type
      obj.value = this.data.value
      this.$refs['data'].validate((valid) => {
        if (valid) {
          this.$http.put('system/sysGlobalConfig', obj).then(({ data: res }) => {
            if (res.code !== 0) {
              return this.$message.error(res.msg)
            }
            this.$message.success('修改成功')
            this.handleClose()
          })
        }
      })
    },
    // handleClose1 () {
    //   this.setHomePageDialog = false
    // },
    // dataActionSubmitHandle1 () {
    //   this.userData.showPage = this.modelSelect
    //   this.$http.put('system/sysUser', this.userData).then(({ data: res }) => {
    //     if (res.code !== 0) {
    //       return this.$message.error(res.msg)
    //     }
    //     this.$message.success('修改成功')
    //     this.handleClose1()
    //   })
    // },
    // 设置是否显示主页
    setHomePage (id, data) {
      this.userData = {
        id: data.id,
        username: data.username,
        realName: data.realName,
        gender: data.gender,
        phone: data.phone,
        email: data.email,
        deptId: data.deptId,
        positionId: data.positionId,
        status: data.status,
        remarks: data.remarks,
        showPage: id
      }
      this.$http.put('system/sysUser', this.userData).then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.$message.success('修改成功')
      })
    },
    // getUserData (id) {
    //   this.$http.get('/getUserInfo').then(({ data: res }) => {
    //     if (res.code !== 0) {
    //       return this.$message.error(res.msg)
    //     }
    //     if (id) {
    //       this.modelSelect = res.data.showPage
    //     }
    //     this.userData = {
    //       id: res.data.id,
    //       username: res.data.username,
    //       realName: res.data.realName,
    //       gender: res.data.gender,
    //       phone: res.data.phone,
    //       email: res.data.email,
    //       deptId: res.data.deptId,
    //       positionId: res.data.positionId,
    //       status: res.data.status,
    //       remarks: res.data.remarks,
    //       showPage: this.modelSelect
    //     }
    //   })
    // },
    getSysGlobalConfig () {
      this.$http.get('system/sysGlobalConfig/getSysGlobalConfig?type=1').then(({ data: res }) => {
        if (res.code !== 0) {
          return this.$message.error(res.msg)
        }
        this.data = res.data
      })
    },
    // 更新短信状态
    switchChange (val) {
      this.switchType.sign = val
      this.putData({ url: this.mixinViewModuleOptions.updateMessageStatusURL,
        paramData: {
          id: this.switchType.id,
          sign: val
        } }).then(res => {
        if (res.code !== 0) {
          return false
        }
      })
    },
    // 获取短信状态
    // getMessageStatus () {
    //   this.getData({
    //     url: this.mixinViewModuleOptions.getBySurfaceNameURL,
    //     paramData: {
    //       surfaceName: 'Note'
    //     }
    //   }).then(res => {
    //     if (res.code !== 0) {
    //       return false
    //     }
    //     this.switchType = Object.assign({}, {}, res.data)
    //   })
    // },
    // 修改用户状态
    setStatus (data, id) {
      this.addOrUpdateItem({
        url: this.mixinViewModuleOptions.updateStatusURL,
        paramData: {
          id,
          status: data
        }
      })
    },
    // 重置密码
    resetPassword (id) {
      this.$confirm('此操作为重置密码, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.putData({
          url: this.mixinViewModuleOptions.resetPasswordURL,
          paramData: {
            id
          }
        }).then(res => {
          if (res.code !== 0) {
            return false
          }
          this.$message.success('重置成功')
        })
      })
    },
    /**
     * @description: 校验字符串是否为字母汉字数字
     * @example: this.checkRule(123) this.checkRule('你好') this.checkRule('hello')
     * @param {string} str 要校验的字符串
     * @return {number} -1:非字母非文字非数字或不存在,1:字母,2:文字,3:数字
     */
    checkRule (str) {
      let results = -1
      if (str) {
        if (/^[a-zA-Z]*$/g.test(str)) { // 字母
          results = 1
        } else if (/^[\u4E00-\u9FA5]+$/.test(str)) { // 文字
          results = 2
        } else if (/^[0-9]*$/g.test(str)) { // 数字
          results = 3
        }
      }
      return results
    },
    querySearch (queryString, cb) {
      let str = ''
      if (this.checkRule(queryString) === -1 || this.checkRule(queryString) === 2) {
        str = `realName=${queryString}`
      } else if (this.checkRule(queryString) === 1) {
        if (!str.length === 1) return
        str = `initial=${queryString}`
      } else if (this.checkRule(queryString) === 3) {
        str = `username=${queryString}`
      }
      if (queryString === '') {
        str = ''
      }
      this.$http.get(`/system/sysUser/getByName?${str}`).then(({ data: res }) => {
        if (res.code !== 0) {
          return
        }
        let temp = res.data || []
        let restaurants = []
        temp.map((item) => {
          restaurants.push({
            value: item.username ? '' + item.username + '(' + item.realName + ')' : '',
            userId: item.id,
            name: item.realName,
            deptName: item.deptName,
            deptId: item.deptId,
            phone: item.phone,
            dept: item.dept
          })
        })
        // 调用 callback 返回建议列表的数据
        cb(restaurants)
      })
    },
    handleSelect (item) {
      this.dataForm.realName = item.name
      this.search()
    },
    // 查询
    search () {
      this.$refs.dataForm.validate((valid) => {
        if (valid) {
          // const param = {}
          this.page = 1
          this.getDataList({ paramData: {
            realName: this.dataForm.realName,
            deptId: this.dataForm.deptId,
            username: this.dataForm.username,
            phone: this.dataForm.phone,
            districtId: this.dataForm.districtId
          } })
        }
      })
    },
    // 获取地区列表
    getDistrictInUser () {
      this.getDataList({ url: this.mixinViewModuleOptions.getDistrictInUserURL }).then(res => {
        if (res.code !== 0) { return }
        this.areaList.push(...res.data)
      })
    },
    getDeptList () {
      // 获取部门列表
      this.getDataList({ url: this.mixinViewModuleOptions.getDeptListURL }).then(res => {
        if (res.code !== 0) { return }
        this.deptList = res.data
        if (!res.data.length) {
          this.deptList.push({
            id: 0,
            name: this.$t('dept.parentNameDefault')
          })
        }
      })
    },
    // 上级部门树, 选中
    deptListTreeCurrentChangeHandle (data) {
      this.dataForm.deptName = data.name
      this.dataForm.deptId = data.id
      this.deptListVisible = false
    },
    // 上级地区树, 选中
    areaListTreeCurrentChangeHandle (data) {
      this.dataForm.districtName = data.name
      this.dataForm.districtId = data.id
      this.areaListVisible = false
    },
    // 同步数据
    addUser (_row) {
      this.loadings = true
      this.$http.post('/system/sysUser/sync').then(({ data: res }) => {
        if (res.code !== 0) {
          this.loadings = false
          return this.$message.error(res.msg)
        }
        if (res.data.sysUserList.length > 0) {
          this.$refs.usererrorList.init(res.data)
        } else {
          this.getDataList()
          this.$message.success('同步成功')
        }
        this.loadings = false
      })
      // this.addVisible = true
      // this.addOrUpdateHandle()
      // this.$http.post('/tb/quartzJob/runJob', {
      //   id: '1'
      // }).then(({ data: res }) => {
      //   if (res.code !== 0) {
      //     return this.$message.error(res.msg)
      //   }
      //   this.$message({
      //     message: this.$t('prompt.success'),
      //     type: 'success',
      //     duration: 500
      //   })
      //   this.getDataList()
      // })
    },
    addPage () {
      this.$refs.usererrorPage.init(1) // 1.同步用户 2.同步部门 3.同步职位
    },
    addWinFace (_row) {
      if (_row) {
        this.$refs.userface.init(_row)
      } else {
        this.$refs.userface.init()
      }
    },
    addWinFingerprint (_row) {
      if (_row) {
        this.$refs.userfingerprint.init(_row)
      } else {
        this.$refs.userfingerprint.init()
      }
    },
    addWinCard (_row) {
      this.$refs.card.init(_row)
    },
    // 修改用户
    editUser (id) {
      this.addVisible = true
      this.addOrUpdateHandle(id)
    },
    // 关闭新增/修改窗口
    clearDialog () {
      this.addVisible = false
      this.getDataList()
    },
    // 删除用户
    deletItmes () {
      let Bool = true
      this.dataListSelections.map(item => {
        if (item.userType !== 0) {
          this.$message({
            message: '选中项含有租户信息，不能进行删除操作',
            type: 'warning'
          })
          Bool = false
        }
      })
      if (!Bool) {
        return false
      }
      this.deleteHandle()
    }
  }
}
</script>
<style lang="scss" scoped>
.user-dialog {
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
}
.download {
  text-decoration: none;
  color: #fff;
}
.tree-input {
  width: 100%;
  position: relative;
  .close {
    position: absolute;
    right: 10px;
    top: 13px;
    font-size: 16px;
    color: #858585;
    cursor: pointer;
    background-color: white;
  }
}
.addBtn {
  ::v-deep .el-form-item__content {
    display: flex;
    .user-switch {
      display: flex;
      align-items: center;
      margin-right: 15px;
      .message-title {
        margin-right: 10px;
      }
    }
  }
}
</style>
